package com.example.xcxhouduan.bean;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class DataResponse {

    @JsonInclude(JsonInclude.Include.NON_EMPTY)
    @JsonProperty("data")
    private Map<String, List<Product>> data = new HashMap<>();

    public DataResponse(List<Product> productList) {
        this.data.put("product", productList);
    }

    public Map<String, List<Product>> getData() {
        return Collections.unmodifiableMap(data);
    }

    public String toJsonString() throws JsonProcessingException {
        ObjectMapper mapper = new ObjectMapper();
        return mapper.writeValueAsString(this);
    }
}